package com.bpmn.system.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bpmn.system.domain.SysApiKeyDataModel;
import com.bpmn.system.domain.query.ApiKeyDataQuery;
import com.bpmn.system.mapper.ApiKeyDataMapper;
import com.bpmn.system.service.IApiKeyDataService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * API Key 数据 Service 实现
 *
 * @author bpmn
 */
@Service
public class ApiKeyDataServiceImpl extends ServiceImpl<ApiKeyDataMapper, SysApiKeyDataModel> implements IApiKeyDataService {

    /**
     * 查询API Key数据列表
     *
     * @param apiKeyDataQuery API Key数据模型
     * @return API Key数据集合
     */
    @Override
    public List<SysApiKeyDataModel> selectApiKeyDataList(ApiKeyDataQuery apiKeyDataQuery) {
        LambdaQueryWrapper<SysApiKeyDataModel> queryWrapper = new LambdaQueryWrapper<>();
        // 根据需要添加查询条件
        queryWrapper.like(StrUtil.isNotBlank(apiKeyDataQuery.getTitle()), SysApiKeyDataModel::getTitle, apiKeyDataQuery.getTitle());
        queryWrapper.eq(StrUtil.isNotBlank(apiKeyDataQuery.getLoginId()), SysApiKeyDataModel::getLoginId, apiKeyDataQuery.getLoginId());
        queryWrapper.orderByDesc(SysApiKeyDataModel::getCreateTime);
        return list(queryWrapper);
    }

    /**
     * 根据API Key查询数据
     *
     * @param apiKey API Key
     * @return API Key数据模型
     */
    @Override
    public SysApiKeyDataModel selectApiKeyDataByApiKey(String apiKey) {
        LambdaQueryWrapper<SysApiKeyDataModel> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysApiKeyDataModel::getApiKey, apiKey);
        return getOne(queryWrapper);
    }

}